﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MDSAdministration
{
    /// <summary>
    /// Interaction logic for ColumnCodeCheck.xaml
    /// </summary>
    public partial class ColumnCodeCheck : UserControl
    {
        public event RoutedEventHandler UncheckedAllColumnHeaders;
        public event RoutedEventHandler CheckedAllColumnHeaders;

        public ColumnCodeCheck()
        {
            InitializeComponent();
        }
        public IEnumerable ItemSource
        {
            get { return dgCode.ItemsSource; }
            set
            {
                dgCode.ItemsSource = value;
            }
        }
        private void Header_CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            HeadCheck(sender, e, true);
        }

        private void Header_CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            HeadCheck(sender, e, false);
        }

        private void HeadCheck(object sender, RoutedEventArgs e, bool IsChecked)
        {
            if (dgCode.Items.SourceCollection != null)
            {
                foreach (object r in dgCode.Items.SourceCollection)
                {
                    if (r.GetType().FullName == Constants.SYSTEM_DATA_DATAROWVIEW)
                    {
                        var dr = (System.Data.DataRowView)r;
                        dr["IsChecked"] = IsChecked;
                    }
                    else
                    {
                        MessageBox.Show("Invalid Data Type been used.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        break;
                    }
                }
                dgCode.Items.Refresh();
            }
            
        }

        private void checkBox_Checked(object sender, RoutedEventArgs e)
        {
            if (CheckedAllColumnHeaders != null)
                CheckedAllColumnHeaders(this, e);
        }

        private void checkBox_Unchecked(object sender, RoutedEventArgs e)
        {
            if (UncheckedAllColumnHeaders != null)
                UncheckedAllColumnHeaders(this, e);
        }
    }
}
